/*
 * =====================================================================================
 *
 *       Filename:  forkalarm.c
 *
 *    Description:  fork and alarm demo
 *
 *
 *        Version:  1.0
 *        Created:  04/20/2012 03:26:36 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Zhiyi Wu (Z.W), zhiyiw@uoregon.edu
 *        Company:  University of Oregon
 *
 * =====================================================================================
 */

#include	"stdio.h"

#include	"stdlib.h"
#include	"signal.h"
#include	"unistd.h"
void handler(int signum){
	if( signum = SIGALRM){
		write(1,"The alarm fired from child\n",30);
	}
}
void main(){

while(1){
	pid_t pid;

	pid = fork();

		signal(SIGALRM, handler);
	if (pid<0) 
	{perror("fork failed!"),exit(1);}

	if (pid ==0)
	{
	write(1,"child\n",10);
//		signal(SIGALRM, handler);
	alarm(5);
	}

	else
	{
	write(1,"parents\n",10);
	wait();
	}

}
}
